package hhAcademicBowl;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextArea;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import javax.swing.JCheckBox;

public class Question {
	
	HHAC manager;
	JFrame frame;
	
	String Question; //regardless of jeopardy's stupid inverse Q&A system I have defined Question as the string to be presented to the viewer.
	String Answer;
	int Value;
	boolean dailyDouble = false;
	

	public Question(HHAC manager, String question, String answer,
			int value, boolean dailyDouble) {
		super();
		this.manager = manager;
		Question = question;
		Answer = answer;
		Value = value;
		this.dailyDouble = dailyDouble;
		initialize();
	}




	@Override
	public String toString() {
		return "Question [Question=" + Question + ", Answer=" + Answer
				+ ", Value=" + Value + ", dailyDouble=" + dailyDouble + "]";
	}

	/**
	 * Initialize the contents of the frame.
	 */
	public void initialize() {
				
		frame = new JFrame();
		frame.getContentPane().setBackground(ColorConstants.BG);
		frame.getContentPane().setLayout(null);
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		//Dimension screen = new Dimension(640,480);
		frame.setBounds(0,0,screen.width,screen.height);
		frame.setUndecorated(true); //maximized
		
		JLabel lblTitle = new JLabel("HH Academic Bowl");
		lblTitle.setHorizontalAlignment(SwingConstants.LEFT);
		lblTitle.setFont(new Font("Impact", Font.PLAIN, 69));
		lblTitle.setBounds((frame.getWidth()-525)/2, 10, 525, 68); //title position
		frame.getContentPane().add(lblTitle);
		
		JTextArea qLabel = new JTextArea();
		qLabel.setWrapStyleWord(true);
		qLabel.setEditable(false);
		qLabel.setBackground(ColorConstants.BG);
		qLabel.setText(Question);
		qLabel.setLineWrap(true);
		qLabel.setFont(new Font("Tahoma", Font.PLAIN, 45));
		
		int qWidth = screen.width / 2;
		qLabel.setBounds((screen.width-qWidth)/2, (lblTitle.getY() + lblTitle.getHeight() + 50), qWidth, (screen.height*2/3));
		frame.getContentPane().add(qLabel);
		
		//CONTROL PANEL------------------------------------------------------------------------------------------
		
		JPanel controlPanel = new JPanel();
		controlPanel.setBorder(null);
		controlPanel.setBackground(ColorConstants.BG);
		int contY = (qLabel.getY() + qLabel.getHeight() + 10);
		controlPanel.setBounds((screen.width-qWidth)/2, contY, qWidth, ((int) screen.getHeight() - contY - 20));
		frame.getContentPane().add(controlPanel);
		controlPanel.setLayout(null);
		
		//SCORING
		JButton btnCheck = new JButton("Check");
		
		
		//final val for checking
		
		final JTextArea ql = qLabel; 
		
		btnCheck.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				ql.setText(Answer);
			}
		});
		btnCheck.setFont(new Font("Tahoma", Font.PLAIN, 20));
		btnCheck.setBounds((controlPanel.getWidth()-150-10), 10, 150, controlPanel.getHeight()-20);
		controlPanel.add(btnCheck);
		
		JCheckBox addToRed = new JCheckBox("Add Points to Red");
		addToRed.setBackground(ColorConstants.BG);
		addToRed.setBounds(10, 10, 130, 10);
		controlPanel.add(addToRed);
		
		JCheckBox subFromRed = new JCheckBox("Subtract Points from Red");
		subFromRed.setBackground(ColorConstants.BG);
		subFromRed.setBounds(10, 30, 170, 10);
		controlPanel.add(subFromRed);
		
		JCheckBox addToBlack = new JCheckBox("Add Points to Black");
		addToBlack.setBackground(ColorConstants.BG);
		addToBlack.setBounds(10, 50, 140, 10);
		controlPanel.add(addToBlack);
		
		JCheckBox subFromBlack = new JCheckBox("Subtract Points from Black");
		subFromBlack.setBackground(ColorConstants.BG);
		subFromBlack.setBounds(10, 70, 180, 10);
		controlPanel.add(subFromBlack);
		
		//final check vals for scoring
		
		final JCheckBox AR = addToRed;
		final JCheckBox SR = subFromRed;
		final JCheckBox AB = addToBlack;
		final JCheckBox SB = subFromBlack;
		final JFrame fr = frame;
		
		//RETURN button
		
		JButton btnReturn = new JButton("return");
		btnReturn.setFont(new Font("Tahoma", Font.PLAIN, 20));
		btnReturn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(AR.isSelected()){
					manager.addToRed(Value);
				}
				if(SR.isSelected()){
					manager.subFromRed(Value);
				}
				if(AB.isSelected()){
					manager.addToBlack(Value);
				}
				if(SB.isSelected()){
					manager.subFromBlack(Value);
				}
				fr.dispose();
				manager.qToG();
			}
		});
		btnReturn.setBounds((controlPanel.getWidth()-150)/2, 10, 150, controlPanel.getHeight()-20);
		controlPanel.add(btnReturn);
		
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
	}
}
